<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\index\controller;
use app\common\controller\Fornt;
use app\common\model\Goods as GoodsModel;
use app\common\model\Cart as CartModel;

class Goods extends Fornt{


  public function jspsdetail($id){
    //初始化模块信息
		parent::initModel(1);
    //获取商品信息
    $info = GoodsModel::get($id);
    //获取购物车信息
    $cinfo = CartModel::getNumAndPrice(['user_id'=>USER_ID]);

    //微信jdk调用
      $script = &  load_wechat('Script');
      $url = $this->request->url(true);
      $options = $script->getJsSign($url);
      if($options===FALSE){
      	// 接口失败的处理
          echo $script->errMsg;
      }

      $this->assign('info', $info);
      $this->assign('options', $options);
      $this->assign('crurl', $url);
      $this->assign('cart', $cinfo);
      return $this->fetch();
  }
  public function qspsdetail($id){
    //初始化模块信息
		parent::initModel(2);
    //获取商品信息
    $info = GoodsModel::get($id);
    //获取购物车信息
    $cinfo = CartModel::getNumAndPrice(['user_id'=>USER_ID]);

    //微信jdk调用
      $script = &  load_wechat('Script');
      $url = $this->request->url(true);
      $options = $script->getJsSign($url);
      if($options===FALSE){
      	// 接口失败的处理
          echo $script->errMsg;
      }

      $this->assign('info', $info);
      $this->assign('options', $options);
      $this->assign('crurl', $url);
      $this->assign('cart', $cinfo);
      return $this->fetch();
  }

  public function detail($id){
    $info = GoodsModel::get($id);
    $cinfo = CartModel::getNumAndPrice(['user_id'=>USER_ID]);

    $map['user_id'] = USER_ID;
		$map['goodsmodel_id'] = ['neq', 2];
		$result = CartModel::destroy($map);


    $script = &  load_wechat('Script');
    // 获取JsApi使用签名，通常这里只需要传 $ur l参数
    $url = $this->request->url(true);
    $options = $script->getJsSign($url);

    // 处理执行结果
    if($options===FALSE){
    	// 接口失败的处理
        echo $script->errMsg;
    }


    $this->assign('info', $info);
    $this->assign('options', $options);
    $this->assign('crurl', $url);

    $this->assign('cart', $cinfo);
    return $this->fetch();
  }

  public function frankdetail($id){
    $info = GoodsModel::get($id);
    $cinfo = CartModel::getNumAndPrice(['user_id'=>USER_ID]);

    $map['user_id'] = USER_ID;
		$map['goodsmodel_id'] = ['neq', 3];
		$result = CartModel::destroy($map);


    $script = &  load_wechat('Script');
    // 获取JsApi使用签名，通常这里只需要传 $ur l参数
    $url = $this->request->url(true);
    $options = $script->getJsSign($url);

    // 处理执行结果
    if($options===FALSE){
    	// 接口失败的处理
        echo $script->errMsg;
    }


    $this->assign('info', $info);
    $this->assign('options', $options);
    $this->assign('crurl', $url);

    $this->assign('cart', $cinfo);
    return $this->fetch();
  }




  	public function qiyedetail($id, $cid){
  		$info = parent::setQiyeCommon();
      $goodInfo = GoodsModel::get($id);
      //删除其他模型的购物车
      $map['user_id'] = USER_ID;
  		$map['goodsmodel_id'] = ['neq', $info['modelInfo']['id']];
  		$result = CartModel::destroy($map);


      $script = &  load_wechat('Script');
      // 获取JsApi使用签名，通常这里只需要传 $ur l参数
      $url = $this->request->url(true);
      $options = $script->getJsSign($url);

      $this->assign('info', $goodInfo);
      $this->assign('options', $options);
      $this->assign('crurl', $url);

      $this->assign('cart', $info['cinfo']);
      return $this->fetch();
  	}


}
